package wechat.rcv.controller;

import com.google.common.base.Objects;
import com.shrcl.engineerprocess.domain.EngineerProjectAssignment;
import com.shrcl.engineerprocess.domain.EngineerProjectAssignmentStatus;
import com.shrcl.engineerprocess.domain.EngineerProjectJob;
import com.shrcl.engineerprocess.domain.EngineerWorkOrder;
import com.shrcl.engineerprocess.domain.WorkSummary;
import edu.fudan.mylang.pf.IObjectFactory;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.log4j.Logger;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.InputOutput;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@SuppressWarnings("all")
public class AssignmentDetail {
  private final static Logger logger = Logger.getLogger(AssignmentDetail.class.getName());
  
  @Autowired
  private IObjectFactory entities;
  
  @RequestMapping(value = "/assignmentdetail")
  public String process(@RequestParam(value = "assignmentId", defaultValue = "") final Long assignmentId, final Model model) {
    String _xblockexpression = null;
    {
      AssignmentDetail.logger.info("=========>AssignmentDetail.processs<============");
      AssignmentDetail.logger.info(("=========>AssignmentDetail.assignmentId<============" + assignmentId));
      String hpage = "error";
      try {
        final EngineerProjectAssignment a = this.entities.<EngineerProjectAssignment>get(EngineerProjectAssignment.class, assignmentId);
        boolean _equals = Objects.equal(a, null);
        if (_equals) {
          model.addAttribute("errormsg", "Invalid id");
        } else {
          model.addAttribute("assignmentId", assignmentId);
          EngineerWorkOrder _workOrder = a.getWorkOrder();
          EngineerProjectJob _projectJob = _workOrder.getProjectJob();
          String _jobName = _projectJob.getJobName();
          model.addAttribute("name", _jobName);
          EngineerWorkOrder _workOrder_1 = a.getWorkOrder();
          String _sid = _workOrder_1.getSid();
          model.addAttribute("orderId", _sid);
          SimpleDateFormat _simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
          Date _startDate = a.getStartDate();
          String _format = _simpleDateFormat.format(_startDate);
          model.addAttribute("startDate", _format);
          SimpleDateFormat _simpleDateFormat_1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
          Date _endDate = a.getEndDate();
          String _format_1 = _simpleDateFormat_1.format(_endDate);
          model.addAttribute("endDate", _format_1);
          EngineerProjectAssignmentStatus _status = a.getStatus();
          String _plus = ("=========>AssignmentDetail.Status<============" + _status);
          InputOutput.<String>println(_plus);
          EngineerProjectAssignmentStatus _status_1 = a.getStatus();
          boolean _equals_1 = Objects.equal(_status_1, EngineerProjectAssignmentStatus.executing);
          if (_equals_1) {
            model.addAttribute("summary", "请输入工作小结");
            model.addAttribute("status", "write");
          } else {
            WorkSummary _dailySummary = a.getDailySummary();
            String _summary = _dailySummary.getSummary();
            String _plus_1 = ("=========>AssignmentDetail.summary<============" + _summary);
            InputOutput.<String>println(_plus_1);
            WorkSummary _dailySummary_1 = a.getDailySummary();
            String _summary_1 = _dailySummary_1.getSummary();
            model.addAttribute("summary", _summary_1);
            model.addAttribute("status", "read");
          }
          hpage = "assignmentdetail";
        }
      } catch (final Throwable _t) {
        if (_t instanceof Exception) {
          final Exception e = (Exception)_t;
          e.printStackTrace();
        } else {
          throw Exceptions.sneakyThrow(_t);
        }
      }
      _xblockexpression = hpage;
    }
    return _xblockexpression;
  }
}
